﻿@page "/Deployments"
@using k8s.Models
@using Mapster
@using Extension
@using BlazorApp.Pages.Common.Html.HTable
@using BlazorApp.Pages.Common.Metadata
@using BlazorApp.Pages.Common
@inherits BlazorApp.Pages.Common.TableBase<V1Deployment>
@if (TableData.PagedItems != null)
{
    <HTable Class="wideTable">
        <HTr>
            <HTd>
                <SearchToolBar Title=@L["Deployment"] Count="@TableData.Total" OnItemDeletedCallback="@(async () => await InvokeAsync(StateHasChanged))"
                               OnSelectedItemCloseClicked="@TableData.RemoveSelection"
                               OnRemoveAllClicked="@TableData.RemoveAllSelection" TableData="@TableData"
                               OnSearch="OnSearchHandler" TItem="V1Deployment"
                               OnNsSelected="OnNsSelectedHandler">

                </SearchToolBar>
            </HTd>
        </HTr>

        <HTr>
            <HTd >
                <Table TItem="V1Deployment"
                       DataSource="@TableData.PagedItems"
                       Size=@TableSize.Small Bordered="true"
                       Total="TableData.Total"
                       @bind-PageIndex="TableData.PageIndex"
                       @bind-PageSize="TableData.PageSize"
                       @bind-SelectedRows="TableData.SelectedRows"
                       Loading="TableData.Loading"
                       OnChange="OnPageChangeHandler">
                    <Selection Key="@(context.Name())"/>
                    <AntDesign.Column Field="@context.Name()" Title=@L["Name"]>
                        <Button OnClick="@(() => OnDeployClick(context))" Type="@ButtonType.Link">@context.Name()</Button>
                    </AntDesign.Column>
                    <AntDesign.Column Field="@context.Namespace()" Title=@L["Namespace"] Width="110px"/>
                    <AntDesign.Column Title=@L["Ready"] TData="int" Width="80px">
                        @($"{context.Status.ReadyReplicas ?? 0}/{context.Status.Replicas ?? 0}")
                    </AntDesign.Column>
                    <AntDesign.Column Title=@L["Desired"] Width="80px" TData="string">
                        <ColorfulTag>@(context.Spec.Replicas ?? 0)</ColorfulTag>
                    </AntDesign.Column>
                    <AntDesign.Column Title=@L["Latest"] TData="int" Width="70px">
                        @(context.Status.UpdatedReplicas ?? 0)
                    </AntDesign.Column>
                    <AntDesign.Column Title=@L["Available"] TData="int" Width="80px">
                        @(context.Status.AvailableReplicas ?? 0)
                    </AntDesign.Column>
                    <AntDesign.Column Title=@L["Selector"] TData="string">
                        <LabelSelectorView LabelSelector="@context.Spec.Selector"></LabelSelectorView>
                    </AntDesign.Column>
                    <AntDesign.Column Title=@L["Images"] TData="string">
                        <ImagesListView PodSpec="@context.Spec.Template.Spec"></ImagesListView>
                    </AntDesign.Column>
                    <AntDesign.Column Title=@L["Age"] TData="string" Width="100px">
                        @context.CreationTimestamp()?.AgeFromUtc()
                    </AntDesign.Column>
                    <AntDesign.Column Title=@L["Condition"] TData="string" Width="150px">
                        <ConditionsTagView Conditions="@(context.Status.Conditions.Adapt<IList<V1Condition>>())"></ConditionsTagView>
                    </AntDesign.Column>
                    <ActionColumn Title=@L["Action"] Width="100px">
                        <DeploymentAction Item="@context"></DeploymentAction>
                    </ActionColumn>
                </Table>
            </HTd>
        </HTr>
    </HTable>

    <ResourceWatcher OnResourceChanged="OnResourceChanged" T="V1Deployment"></ResourceWatcher>
}
